<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>

<body>
  <!DOCTYPE html>
  <html lang="en">

  <head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
  </head>

  <body>
    <script>
      function fn(N, M) {
        return Math.floor(Math.random() * (M - N + 1) + N)
      }
      let ran = fn(1, 10)

      // while (true) {
      //   let num = +prompt('请输入一个数字')
      //   if (num > ran) {
      //     alert('猜大了，继续踩')
      //   } else if (num < ran) {
      //     alert('猜小了，继续踩')
      //   } else {
      //     alert('猜对啦')
      //     break
      //   }
      // }
      let flag = true

      for (let i = 1; i <= 3; i++) {
        let num = +prompt('请输入一个数字')
        if (num > ran) {
          alert(`猜大了，继续踩,还剩${3 - i}`)
        } else if (num < ran) {
          alert(`猜小了，继续踩,还剩${3 - i}`)
        } else {
          flag = false
          alert('猜对啦')
          break
        }
      }

      if (flag) alert('3次机会没了')




    </script>
  </body>

  </html>
</body>

</html>